#include <stdio.h>
/***************************************************************************                                                                      *
* Params: buffer - pointer to image in memory                              *
*         rows - number of rows in image                                   *
*         cols - number of columns in image                                *
*         x_scale - scale factor in X direction                            *
*         y_scale - scale factor in Y direction                            *
****************************************************************************/
typedef struct pixel{
    unsigned char b,g,r;
} pixel;

typedef pixel* pixel_ptr;

void scale_data(unsigned char* buffer, unsigned char* image_buff, int cols, 
		int rows, int new_cols, int new_rows)
{
    	unsigned long x, y;          /* loop indices for columns and rows */
    	unsigned long index;        /* index into line buffer */
    	unsigned long source_index; /* address of source pixel in image buffer */
    	unsigned char *line_buff;   /* output line buffer */
    	unsigned line;              /* number of pixels in one scan line */
    	unsigned long x_source, y_source;  /* x and y address of source pixel */
    	pixel_ptr color_buff;       /* pointer to a color image in memory */
	
	float x_scale, y_scale;


	x_scale = new_cols / (cols*1.0);
	y_scale = new_rows / (rows*1.0);
	
	color_buff = (pixel_ptr) buffer;
	
	line_buff = image_buff;

	
    	for(y=0; y< new_rows; y++) {
		for(x=0; x< new_cols; x++) {
			x_source = (unsigned long)((x / x_scale)+ 0.5);
			y_source = (unsigned long)((y / y_scale)+ 0.5);
			source_index = (y_source*cols + x_source);

			*line_buff++ = color_buff[source_index].b;
			*line_buff++ = color_buff[source_index].g;
			*line_buff++ = color_buff[source_index].r;
			

		}
	}
}



